<template>
    <div>
        <la-dialog
            ref="dialogRef"
            :title="dialogTitle"
            :async="true"
            width="550px"
            @confirm="handleSubmit"
            @cancel="handleClose"
        >
            <el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
               
                <el-form-item label="名称">
                    <el-input v-model="formData.name" />
                </el-form-item>
            
               
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="formData.description" />
                </el-form-item>
                
                
                
            </el-form>
            
        </la-dialog>
    </div>
</template>
<script>
import api from "@/app/admin/api";
import laDialog from "@/lite/components/la-dialog/index.vue";
export default {
  components: {
    laDialog
  },
  data() {
    return {
        mode:'add',
        formData:{
            type:'1',
            icon:'',
        },
        formRules:{}
    }
},
computed:{
    dialogTitle(){
        return this.mode == 'add'?'添加':'编辑';
    }
},
methods:{
    async setFormData(row){
        const res = await api.role.read({id:row.id})
        this.formData = res.data;
    },
    open(type = 'add'){
        this.mode = type;
        this.$refs.dialogRef.open()
        return this;
    },
    close(){
        this.$emit('close')
    },
    async handleSubmit(){
        if(this.mode == 'add'){
            const res = await api.role.create(this.formData)
        }else{
            const res = await api.role.update(this.formData)
        }
       
        this.close()
        this.$emit('success');
    },
    handleClose(){
        console.log(99)
        this.close()
    }
}
}
</script>
